var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');

var app = getApp();

Page({
  data: {
    type: 0,
    page: 1,
    size: 10,
    totalPages: 1,
    list:{},
    titleList:["积分","爱币"],
    detailList:{},
    detail:{}
  },
  onPullDownRefresh(){
    wx.showNavigationBarLoading() //在标题栏中显示加载
    this.getListData()
    wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh() //停止下拉刷新  
    },

  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    this.setData({

     });
   },
  onReady: function () {
    // 页面渲染完成

  },
  onShow: function () {
    // 页面显示
   this.getListData()
  },
  getListData: function(){
    var that = this;
    util.request(api.WalletList).then(function (res) {
      if (res.errno === 0) {
        that.setData({
          list: res.data
        });
        if (that.data.list.mobile === "" || that.data.list.mobile == undefined){
          wx.redirectTo({
            url: "/pages/auth/bindMobile/bindMobile"
          });
        }
      }
    });
  },
  
  onHide: function () {
    // 页面隐藏

  },
  onUnload: function () {
    // 页面关闭

  },
  payBalance:function(){
    if (app.globalData.hasLogin) {
      wx.navigateTo({
        url: "/pages/ucenter/payWallet/payWallet"
      });
    } else {
      wx.navigateTo({
        url: "/pages/auth/login/login"
      });
    }
  },
  getDetailList:function(){
    if (app.globalData.hasLogin) {
      wx.navigateTo({
        url: "/pages/ucenter/payList/payList"
      });
    } else {
      wx.navigateTo({
        url: "/pages/auth/login/login"
      });
    }
  },
  updateSecret:function(){
    if (app.globalData.hasLogin) {
      wx.navigateTo({
        url: "/pages/ucenter/updatePayPassword/updatePayPassword"
      });
    } else {
      wx.navigateTo({
        url: "/pages/auth/login/login"
      });
    }
  },
  getIntegral:function(){
    if (app.globalData.hasLogin) {
      var balance = this.data.list.balance;
      wx.navigateTo({
        url: "/pages/ucenter/exchangeIntegral/exchangeIntegral?balance=" + balance 
      });
    } else {
      wx.navigateTo({
        url: "/pages/auth/login/login"
      });
    }
  }
  
})